# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=shapelib

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.0
pkgrel=1
pkgdesc="simple C API for reading and writing ESRI Shapefiles (mingw-w64)"
arch=('any')
url="http://shapelib.maptools.org/"
license=("LGPL" "MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-proj")
options=(strip staticlibs)
source=("http://download.osgeo.org/shapelib/${_realname}-${pkgver}.tar.gz"
    shapelib_autotools.patch
    shapelib_backports.patch)
sha1sums=('599fde6f69424fa55da281506b297f3976585b85'
          'a0eb9196591e5f5841b2de09e29bf04a40cd475d'
          '4ae20269dd1c62679fd132baf7c1cc194af89f7f')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/shapelib_autotools.patch
  patch -p1 -i ${srcdir}/shapelib_backports.patch

  NOCONFIGURE=1 sh ./autogen.sh
}

build() {
  #export lt_cv_deplibs_check_method='pass_all'
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  "${srcdir}"/${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="$pkgdir" install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}
